/** 
  
*/
<template>
    <div>
        <div v-if="ifShowList === 'list'">
            <condition-card
                @reset="reset"
                @search="onSubmit"
                label-position="right"
                label-width="150px"
            >
                <el-row :gutter="24" style="height: 50px;">
                    <el-col :span="8">
                        <el-form-item label="项目开始时间">
                            <el-date-picker
                                v-model="queryForm.condition.conferenceStartTime"
                                type="date"
                                style="width:100%"
                                :disabled="ifShowDetail"
                                value-format="yyyy-MM-dd HH:mm:ss"
                                :picker-options="startDatePicker"
                            ></el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="项目结束时间">
                            <el-date-picker
                                v-model="queryForm.condition.conferenceEndTime"
                                type="date"
                                style="width:100%"
                                :disabled="ifShowDetail"
                                value-format="yyyy-MM-dd HH:mm:ss"
                                :picker-options="endDatePicker"
                            ></el-date-picker>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="培养层次">
                            <el-select
                                v-model.trim="queryForm.condition.faculty"
                                clearable
                                filterable
                                style="width: 100%"
                            >
                                <el-option
                                    v-for="item in options.teachLevel"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row :gutter="24" style="height: 50px;">
                    <el-col :span="8">
                        <el-form-item label="留学内容">
                            <el-input
                                v-model="queryForm.condition.versionCode"
                                class="topic-input-select"
                                maxlength="32"
                            ></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="启用状态">
                            <el-select
                                v-model.trim="queryForm.condition.faculty"
                                clearable
                                filterable
                                style="width: 100%"
                            >
                                <el-option
                                    v-for="item in options.teachLevel"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value"
                                ></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <!-- 搜索框结束 -->

                <!-- 列表页开始 -->
            </condition-card>
            <el-card shadow="never" v-loading="loading" body-style="padding: 24px;">
                <h1 class="condition-title">校级交流项目</h1>
                <div class="sub-title">
                    <div class="float-right" style="display: flex;">
                        <!-- 删除 -->
                        <el-button type="danger" @click="teacherAudit()">删除</el-button>
                        <!-- 新增 -->
                        <el-button type="primary" @click="adminAdd()">新增</el-button>
                    </div>
                </div>
                <edu-table
                    :pagination="false"
                    :order="true"
                    :tooltipEffect="tooltipEffect"
                    stripe
                    :data="dataList"
                    size="mini"
                    @selection-change="handleSelectionChange"
                >
                    <edu-table-column label="培养层次" prop="oneSubjectNameCN"></edu-table-column>
                    <edu-table-column label="项目名称" prop="englishName"></edu-table-column>
                    <edu-table-column label="项目联系人" prop="englishName"></edu-table-column>
                    <edu-table-column label="国家" prop="englishName"></edu-table-column>
                    <edu-table-column label="合作大学" prop="englishNameAbbreviation"></edu-table-column>
                    <edu-table-column label="项目开始时间" prop="name" width="120"></edu-table-column>
                    <edu-table-column label="项目结束时间" prop="conferenceWebsite" width="120"></edu-table-column>
                    <edu-table-column label="每年的中方留学生名额" prop="conferenceLevelName" width="160"></edu-table-column>
                    <edu-table-column label="每年的外方留学生名额" prop="conferenceFrequency" width="160"></edu-table-column>
                    <edu-table-column label="留学内容" prop="remark"></edu-table-column>
                    <edu-table-column label="启用状态" prop="remark"></edu-table-column>
                    <!-- 操作 -->
                    <edu-table-column :label="$t('base.operate')" fit width="200">
                        <template slot-scope="scope">
                            <el-button type="text" @click="viewAudit(scope.row)">查看</el-button>
                            <el-button type="text" @click="test(scope.row, 'delOne')">停用</el-button>
                            <el-button type="text" @click="test(scope.row, 'delOne')">编辑</el-button>
                            <el-button type="text" @click="audit(scope.row, 'audit')">删除</el-button>
                        </template>
                    </edu-table-column>
                </edu-table>
                <el-row type="flex" class="row-bg" justify="end">
                    <el-col>
                        <el-pagination
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                            :current-page="queryForm.pageNum_"
                            :page-sizes="[20, 40, 80, 100]"
                            :page-size="queryForm.pageSize_"
                            layout="total, sizes, prev, pager, next, jumper"
                            :total="queryForm.total_"
                            style="float:right;margin-top:10px"
                        ></el-pagination>
                    </el-col>
                </el-row>
            </el-card>
        </div>
        <div v-if="ifShowList ==='view'">
            <inter-School-Com-View @returnVal="changekey"></inter-School-Com-View>
        </div>
        <div v-if="ifShowList ==='add'">
            <inter-School-Com-App
                @returnVal="changekey"
                :submitType="submitType"
                :id="id"
                :pageFrom="pageFrom"
            ></inter-School-Com-App>
        </div>
    </div>
</template>
<script>
import conOfIntAcaConApi from 'common/src/api/internationalCommunication/conOfIntAcaCon'
import { queryDic } from 'common/src/api/dictionary'
import UTILS from 'common/src/utils/utils'
import InterSchoolComApp from './InterSchoolComApp'
import InterSchoolComView from './common/InterSchoolComView'
export default {
    components: {
        'inter-School-Com-View': InterSchoolComView,
        'inter-School-Com-App': InterSchoolComApp
    },
    data() {
        return {
            queryForm: {
                pageNum_: 1,
                pageSize_: 20,
                total_: 0,
                condition: {
                    faculty: '',
                    conferenceLevel: '',
                    versionCode: '',
                    name: '',
                    country: '',
                    conferenceEndTime: '',
                    conferenceStartTime: ''
                }
            },
            submitType: '',
            pageFrom: '',
            id: '',
            dataList: [],
            contentForm: {
                content: ''
            },
            ifShowList: 'list',
            dialogFormVisible: false,
            multipleSelection: {
                ids: []
            },
            options: {
                country: [],
                teachLevel: [],
                states: [
                    {
                        label: '草稿',
                        value: 0
                    },
                    {
                        label: '待审核',
                        value: 1
                    },
                    {
                        label: '审核中',
                        value: 2
                    },
                    {
                        label: '已驳回',
                        value: 3
                    },
                    {
                        label: '已通过',
                        value: 4
                    },
                    {
                        label: '不通过',
                        value: 5
                    }
                ]
            }
        }
    },
    computed: {
        pickerOptions() {
            let _this = this
            return {
                disabledDate: time => {
                    let nowData = new Date(_this.maxCode.slice(0, 4) + '-' + _this.maxCode.slice(4))
                    nowData = new Date(nowData.setDate(nowData.getDate() - 1))
                    return time < nowData
                }
            }
        }
    },
    created() {
        // 初始化列表页
        this.getListData()
        this.getCountry()
        this.getTeacherLevel()
    },
    methods: {
        // 字典获取 国家
        async getCountry() {
            // 筛选条件字典查询
            let data = {
                lang: this.$store.getters.language || 'cn',
                type: 'allChild',
                keys: [
                    'G_GJQU' // 国家/地区
                ]
            }
            await queryDic(data).then(res => {
                UTILS.fillSelect(
                    {
                        country: 'G_GJQU' // 国家/地区
                    },
                    res.data,
                    this.options
                )
            })
        },

        // 字典获取培养层次
        async getTeacherLevel() {
            // 筛选条件字典查询
            let data = {
                lang: this.$store.getters.language || 'cn',
                type: 'allChild',
                keys: [
                    'X_PYCC' // 培养层次
                ]
            }
            await queryDic(data).then(res => {
                UTILS.fillSelect(
                    {
                        teachLevel: 'X_PYCC' // 培养层次
                    },
                    res.data,
                    this.options
                )
            })
        },
        test() {},
        // 导出目录
        exportMenu() {
            let _this = this
            let parm = {
                conferenceLevel: this.queryForm.condition.conferenceLevel,
                faculty: this.queryForm.condition.faculty,
                versionCode: this.queryForm.condition.versionCode,
                name: this.queryForm.condition.name,
                ids: this.multipleSelection.ids
            }
            conOfIntAcaConApi.exportExcelF(parm).then(res => {
                if (res.data && res.data.key) {
                    setTimeout(() => {
                        conOfIntAcaConApi.exportExcelS(res.data.key).then(resS => {
                            if (resS.data && resS.data.path) {
                                conOfIntAcaConApi.exportExcelT(resS.data.path).then(resT => {
                                    _this.$message({
                                        message: _this.$t('base.exportSuccess'),
                                        type: 'success'
                                    })
                                })
                            } else {
                                _this.exportMenu()
                            }
                        })
                    }, 3000)
                }
            })
        },
        // 申请页返回
        changekey(val) {
            this.ifShowList = val
            this.getListData()
        },
        // 新增
        adminAdd() {
            this.ifShowList = 'add'
            this.submitType = 'add'
            this.pageFrom = 'admin'
            this.id = ''
        },
        teacherAudit() {
            this.dialogFormVisible = true
        },

        // 查看
        viewAudit() {
            this.ifShowList = 'view'
        },
        // 查看
        audit(val) {
            this.ifShowList = 'audit'
        },

        // 重置筛选框
        reset() {
            this.queryForm = {
                pageNum_: 1,
                pageSize_: 20,
                total_: 0,
                condition: {
                    faculty: '',
                    versionCode: '',
                    name: '',
                    conferenceLevel: ''
                }
            }
            this.getListData()
        },

        // 查询按钮
        onSubmit() {
            this.queryForm.pageNum_ = 1
            this.queryForm.total_ = 0
            this.queryForm.pageSize_ = 20
            this.getListData()
        },

        // 获取列表
        getListData() {
            let _this = this
            this.dataList = []
            conOfIntAcaConApi.getConferenceList(this.queryForm).then(res => {
                res.data.list.forEach(revList => {
                    _this.dataList.push(revList)
                    _this.queryForm.pageSize_ = res.data.pageSize_
                    _this.queryForm.total_ = res.data.total_
                    _this.queryForm.pageNum_ = res.data.pageNum_
                })
            })
        },
        handleSelectionChange(val) {
            this.multipleSelection.ids = []
            val.forEach(menu => {
                this.multipleSelection.ids.push(menu.id)
            })
        },
        handleSizeChange(val) {
            this.queryForm.pageSize_ = val
            this.getListData()
        },
        handleCurrentChange(val) {
            this.queryForm.pageNum_ = val
            this.getListData()
        }
    }
}
</script>
<style lang="scss" scoped>
.condition-title {
    color: #2b3b4e;
    font-size: 18px;
    line-height: 24px;
    font-weight: bold;
}
.sub-title {
    margin: 16px 0 65px 0;
    font-size: 16px;
    color: #000020;
    letter-spacing: 0;
}
</style>
